package net.jlibrary.student.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.springframework.stereotype.Component;

import net.jlibrary.common.core.annotation.CodeGenComment;
import net.jlibrary.common.core.annotation.Compositor;
import net.jlibrary.common.core.annotation.SearchCondition;
import net.jlibrary.common.core.annotation.SearchField;
import net.jlibrary.common.core.entity.BaseObject;

@Entity(name = "t_student")
@Component
@Compositor("createdate desc")
@CodeGenComment(value = "学生管理", genSelect = true)
public class Student extends BaseObject {
	private static final long serialVersionUID = 4964787706703021956L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@SearchField(value = "id", condition = SearchCondition.EQUAL)
	private Long id;

	private String name;

	private Integer age;

	private Integer sex;

	// private Integer specialty_id;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "specialty_id")
	@CodeGenComment(value = "专业种类", viewList = true, viewSearch = true, required = true)
	private Specialty specialty;

	@SearchField(value = "specialty", condition = SearchCondition.EQUAL)
	@Transient
	private Specialty specialtySearchKey;

	@Column(updatable = false)
	@Temporal(TemporalType.TIMESTAMP)
	@CodeGenComment(value = "创建时间", viewList = true)
	private Date createdate;
	@Temporal(TemporalType.TIMESTAMP)
	private Date lastdate;

	@SearchField(value = "name", condition = SearchCondition.FUZZ_FULL)
	@Transient
	private String nameSearchKey;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public Integer getSex() {
		return sex;
	}

	public void setSex(Integer sex) {
		this.sex = sex;
	}

	public static long getSerialVersionUID() {
		return serialVersionUID;
	}

	public Specialty getSpecialty() {
		return specialty;
	}

	public void setSpecialty(Specialty specialty) {
		this.specialty = specialty;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Student other = (Student) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	public String getNameSearchKey() {
		return nameSearchKey;
	}

	public void setNameSearchKey(String nameSearchKey) {
		this.nameSearchKey = nameSearchKey;
	}

	public Specialty getSpecialtySearchKey() {
		return specialtySearchKey;
	}

	public void setSpecialtySearchKey(Specialty specialtySearchKey) {
		this.specialtySearchKey = specialtySearchKey;
	}

	@Override
	public Serializable getPrimaryKey() {
		return id;
	}

	@Override
	public Date getCreatedate() {
		return createdate;
	}

	@Override
	public void setCreatedate(Date createdate) {
		this.createdate = createdate;
	}

	@Override
	public Date getLastdate() {
		return lastdate;
	}

	@Override
	public void setLastdate(Date lastdate) {
		this.lastdate = lastdate;
	}

//	public Integer getSpecialty_id() {
//		return specialty_id;
//	}
//
//	public void setSpecialty_id(Integer specialty_id) {
//		this.specialty_id = specialty_id;
//	}

}
